package com.wangcang.widgetlibrary.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.wangcang.widgetlibrary.R;

/**
 * @author feng.gao
 * @date 2017-7-5 上午10:22:57
 * @description
 */
public class OptionDialog extends BaseDialog {
    private Button item1Btn;
    private Button item2Btn;
    private Button cancleBtn;
    private BaseDialog.IOnDialogItemListener listener;

    public OptionDialog(Context context, IOnDialogItemListener listener, String[] items) {
        super(context);
        // TODO Auto-generated constructor stub
        this.listener = listener;
        this.items = items;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_option);
        item1Btn = (Button) findViewById(R.id.btn_tack_photo);
        item2Btn = (Button) findViewById(R.id.btn_photos);
        Button cancelBtn = (Button) findViewById(R.id.btn_cancel);

        item1Btn.setOnClickListener(this);
        item2Btn.setOnClickListener(this);
        cancelBtn.setOnClickListener(this);
        item1Btn.setText(items[0]);
        item2Btn.setText(items[1]);
        if (items.length > 2) {
            cancelBtn.setText(items[2]);
        }
    }



    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        super.onClick(v);
        if (v.getId() == R.id.btn_tack_photo) {
            listener.onDialogItemSelected(0);
        } else if (v.getId() == R.id.btn_photos) {
            listener.onDialogItemSelected(1);
        } else if (v.getId() == R.id.btn_cancel) {
            if (items.length > 2) {
                listener.onDialogItemSelected(2);
            } else {
                this.dismiss();
            }
        }

    }

}